package com.ruoyi.web.controller.safety;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.control.domain.RyssHistory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safety.domain.SafetyPointAbnormal;
import com.ruoyi.safety.service.ISafetyPointAbnormalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测点异常信息数据Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/safety/abnormal")
public class SafetyPointAbnormalController extends BaseController {
    @Autowired
    private ISafetyPointAbnormalService safetyPointAbnormalService;

    /**
     * 查询测点异常信息数据列表
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafetyPointAbnormal safetyPointAbnormal) {
        startPage();
        List<SafetyPointAbnormal> list = safetyPointAbnormalService.selectSafetyPointAbnormalList(safetyPointAbnormal);
        return getDataTable(list);
    }

    /**
     * 导出测点异常信息数据列表
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:export')")
    @Log(title = "测点异常信息数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyPointAbnormal safetyPointAbnormal) {
        List<SafetyPointAbnormal> list = safetyPointAbnormalService.selectSafetyPointAbnormalList(safetyPointAbnormal);
        ExcelUtil<SafetyPointAbnormal> util = new ExcelUtil<SafetyPointAbnormal>(SafetyPointAbnormal.class);
        util.exportExcel(response, list, "测点异常信息数据数据");
    }

    /**
     * 获取测点异常信息数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:query')")
    @GetMapping(value = "/{pointCode}")
    public AjaxResult getInfo(@PathVariable("pointCode") String pointCode) {
        return success(safetyPointAbnormalService.selectSafetyPointAbnormalByPointCode(pointCode));
    }

    /**
     * 新增测点异常信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:add')")
    @Log(title = "测点异常信息数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyPointAbnormal safetyPointAbnormal) {
        return toAjax(safetyPointAbnormalService.insertSafetyPointAbnormal(safetyPointAbnormal));
    }

    /**
     * 修改测点异常信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:edit')")
    @Log(title = "测点异常信息数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyPointAbnormal safetyPointAbnormal) {
        return toAjax(safetyPointAbnormalService.updateSafetyPointAbnormal(safetyPointAbnormal));
    }

    /**
     * 删除测点异常信息数据
     */
    @PreAuthorize("@ss.hasPermi('safety:abnormal:remove')")
    @Log(title = "测点异常信息数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pointCodes}")
    public AjaxResult remove(@PathVariable String[] pointCodes) {
        return toAjax(safetyPointAbnormalService.deleteSafetyPointAbnormalByPointCodes(pointCodes));
    }


    /**
     * 根据传感器名称、异常类型  查询异常传感器总数
     */
    @GetMapping("/getAbnormalTotal")
    public int getAbnormalTotal(@RequestParam(value = "sensorTypeName", required = true) String sensorTypeName,
                                @RequestParam(value = "abnormalType", required = true) String abnormalType) {
        int total = safetyPointAbnormalService.getAbnormalTotal(sensorTypeName, abnormalType);
        return total;
    }

    /**
     * 传感器断线数量
     */
    @GetMapping("/getSensorDisconnectionTotal")
    public int getSensorDisconnectionTotal() {
        int total = safetyPointAbnormalService.getSensorDisconnectionTotal();
        return total;
    }

    /**
     * 最近24小时故障报警     异常类型 ！= 上限、超上限
     */
    @GetMapping("/getFaultTotal")
    public TableDataInfo getFaultTotal() {
        List<SafetyPointAbnormal> list =  safetyPointAbnormalService.getFaultTotal();
        return getDataTable(list);
    }


    /**
     * 报警趋势  瓦斯、7日报警次数
     */
    @GetMapping("/getWscxValueList")
    public List getWscxValueList() {
        List<String> list = safetyPointAbnormalService.getWscxValueList();
        return list;
    }

    /**
     *
     * @return一氧化碳7日报警次数
     */
    @GetMapping("/getYyhtValueList")
    public List getYyhtValueList() {
        List<String> list = safetyPointAbnormalService.getYyhtValueList();
        return list;
    }


    /**
     * 根据传感器名称  查询  近3天设备（传感器）故障数量
     */
    @GetMapping("/getDeviceAbnormalTotal")
    public int getDeviceAbnormalTotal(@RequestParam(value = "sensorTypeName", required = true) String sensorTypeName) {
        int total = safetyPointAbnormalService.getDeviceAbnormalTotal(sensorTypeName);
        return total;
    }


    /**
     * 1日内异常点位数量
     */
    @GetMapping("/getOneDayAbnormalTotal")
    public int getOneDayAbnormalTotal() {
        int total = safetyPointAbnormalService.getOneDayAbnormalTotal();
        return total;
    }


    /**
     * 大营大屏报警趋势  瓦斯、7日报警次数
     */
    @GetMapping("/getDyDpWscxValueList")
    public List getDyDpWscxValueList() {
        List<String> list = safetyPointAbnormalService.getDyDpWscxValueList();
        return list;
    }
}
